package Test;

class Food {
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Banana extends Fruit {
}

class plate<T> {
    private T message ;
    public T getMessage() {
        return message;
    }
    public void setMessage(T message) {
        this.message = message;
    }
}

public class WildCard {

    public static void main(String[] args) {
        plate<Fruit> message = new plate<>();

        message.setMessage(new Fruit());

        plate<Food> message1 = new plate<>();
        message1.setMessage(new Food());

        fun3(message);
        fun3(message1);
    }

    //通配符的下届

    public static void fun3(plate<? super Fruit> temp){
        temp.setMessage(new Banana());
        temp.setMessage(new Apple()); //此时是可以设置
        //Fruit fruit = temp.getMessage(); //不能确定，所以不能接收，万一是Food呢，Object是所有类的父类，所以肯定可以接收
        System.out.println(temp.getMessage());
    }



    public static void main2(String[] args) {
        plate<Apple> message = new plate<>();

        message.setMessage(new Apple());

        plate<Banana> message1 = new plate<>();
        message1.setMessage(new Banana());

        fun(message);
        fun(message1);

    }


    //通配符的上界

    public static void fun(plate<? extends Fruit> temp){
        //temp.getMessage(new Banana());
        //temp.getMessage(new Apple()); Fruit的子类有很多，所以不能添加
        System.out.println(temp.getMessage());
    }


//    public static void main1(String[] args) {
//        plate<String> message = new plate<>() ;
//        message.setMessage("欢迎观看");
//        fun1(message);
//
//        plate<Integer> message2 = new plate<>() ;
//        message2.setMessage(123);
//        fun1(message2);
//    }
//
//    public static void fun1(plate<?> temp){
//        //temp.setMessage(12);//不能进行元素的修改
//        System.out.println(temp.getMessage());
//    }

}
